﻿using System;
using System.Net;
using System.Net.Sockets;
using Reflection = System.Reflection;

namespace Kit.LogMonitor {
    /// <summary>
    /// 
    /// </summary>
    internal class Common {
        /// <summary>
        /// 
        /// </summary>
        static Common() {
            try {

            } catch { }
        }
        /// <summary>
        /// 建立缓存[滑动过期]
        /// </summary>
        /// <param name="Key"></param>
        /// <param name="Value"></param>
        /// <param name="Dependencies">设置缓存有效的依赖性</param>
        /// <param name="Seconds">时间间隔(秒),设置最后一次访问后间隔多长时间过期</param>
        /// <param name="Removed">设置在清除缓存时引发的事件</param>
        public static void Insert(string Key, object Value, int Seconds, CacheDependency Dependencies = null, CacheItemRemovedCallback Removed = null) {
            if (Value != null) {
                Redis.Insert(Key, Value, Dependencies, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(Convert.ToDouble(Seconds)), CacheItemPriority.Normal, Removed);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public static string IPV4 { get; private set; }
        /// <summary>
        /// 
        /// </summary>
        public static string IP {
            get {
                try {
                    return Cliente.GetProperty("IP").GetValue(null).ToString();
                } catch {
                    return null;
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public static string Page {
            get {
                try {
                    return Cliente.GetProperty("Page").GetValue(null).ToString();
                } catch {
                    return null;
                }
            }
        }
        /// <summary>
        /// 获取当前访问页的数据传输方式
        /// </summary>
        public static string RequestType {
            get {
                try {
                    return Cliente.GetProperty("RequestType").GetValue(null).ToString();
                } catch {
                    return null;
                }
            }
        }
        /// <summary>
        /// 获取当前访问页面的POST数据
        /// </summary>
        public static string POST {
            get {
                try {
                    return Cliente.GetProperty("POST").GetValue(null).ToString();
                } catch {
                    return null;
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public static string System {
            get {
                try {
                    return Cliente.GetProperty("System").GetValue(null).ToString();
                } catch {
                    return null;
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public static string LoginName {
            get {
                try {
                    return Cliente.GetProperty("LoginName").GetValue(null).ToString();
                } catch {
                    return null;
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public static string Name {
            get {
                try {
                    return Cliente.GetProperty("Name").GetValue(null).ToString();
                } catch {
                    return null;
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public static int UID {
            get {
                try {
                    return (int)Cliente.GetProperty("UID").GetValue(null);
                } catch {
                    return 0;
                }
            }
        }
        /// <summary>
        /// 角色类型
        /// </summary>
        public static string PermissionType {
            get {
                try {
                    return Cliente.GetProperty("PermissionType").GetValue(null).ToString();
                } catch {
                    return null;
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public static string UserAgent {
            get {
                try {
                    return Cliente.GetProperty("UserAgent").GetValue(null).ToString();
                } catch {
                    return null;
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public static string SiteKey {
            get {
                try {
                    return Cliente.GetProperty("SiteKey").GetValue(null).ToString();
                } catch {
                    return null;
                }
            }
        }
    }
}
